package com.yunyi.user.controller;

import com.yunyi.model.company.Company;
import com.yunyi.response.CommonCode;
import com.yunyi.response.QueryResponseResult;
import com.yunyi.response.QueryResult;
import com.yunyi.response.ResponseResult;
import com.yunyi.user.service.CompanyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CompanyController
 * @Description 用人单位信息
 * @Author leizhang
 * Date 2021/8/20 11:33 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/companyApi")
public class CompanyController {
    private static Logger LOGGER = LoggerFactory.getLogger(CompanyController.class);
    @Autowired
    private CompanyService companyService;

    /**
     * @Description : 用人单位列表信息获取
     * @Author : leizhang
     * @Date 12:25 上午 2021/8/21
     * @param requestParam
     * @return com.yunyi.response.QueryResponseResult
     **/
    @GetMapping("/getCompanyInfo")
    public QueryResponseResult getCompanyInfo(@RequestParam Map<String, Object> requestParam) {
        try {
            List<Company> companyInfos = companyService.getCompanyInfos(requestParam);
            QueryResult<Company> queryResult = new QueryResult<>();
            queryResult.setTotal(companyInfos.size());
            queryResult.setList(companyInfos);
            return new QueryResponseResult(CommonCode.SUCCESS,queryResult);
        } catch (Exception e) {
            LOGGER.error("用人单位信息获取失败:[{}]", e.getMessage(), e);
            return new QueryResponseResult(CommonCode.FAIL,null);
        }
    }

}
